<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Enables the ability to use PHP functions as XSLT functions</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="xsltprocessor.importstylesheet.html">« XSLTProcessor::importStylesheet</a></li>
      <li style="float: right;"><a href="xsltprocessor.removeparameter.html">XSLTProcessor::removeParameter »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.xsltprocessor.html">XSLTProcessor</a></li>
    <li>Enables the ability to use PHP functions as XSLT functions</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="xsltprocessor.registerphpfunctions" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">XSLTProcessor::registerPHPFunctions</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.4, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">XSLTProcessor::registerPHPFunctions</span> &mdash; <span class="dc-title">Enables the ability to use PHP functions as XSLT functions</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-xsltprocessor.registerphpfunctions-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>XSLTProcessor::registerPHPFunctions</strong></span>(<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$functions</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   This method enables the ability to use PHP functions as XSLT functions
   within XSL stylesheets.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-xsltprocessor.registerphpfunctions-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">functions</code></dt>

     <dd>

      <p class="para">
       Use this parameter to only allow certain functions to be called from 
       XSLT.
      </p>
      <p class="para">
       This parameter can be either a string (a function name) or an array of
       functions.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-xsltprocessor.registerphpfunctions-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-xsltprocessor.registerphpfunctions-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5504">
    <p><strong>示例 #1 Simple PHP Function call from a stylesheet</strong></p>
    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOB<br /></span><span style="color: #DD0000">&lt;allusers&gt;<br />&nbsp;&lt;user&gt;<br />&nbsp;&nbsp;&lt;uid&gt;bob&lt;/uid&gt;<br />&nbsp;&lt;/user&gt;<br />&nbsp;&lt;user&gt;<br />&nbsp;&nbsp;&lt;uid&gt;joe&lt;/uid&gt;<br />&nbsp;&lt;/user&gt;<br />&lt;/allusers&gt;<br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xsl&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOB<br /></span><span style="color: #DD0000">&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;<br />&lt;xsl:stylesheet&nbsp;version="1.0"&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:php="http://php.net/xsl"&gt;<br />&lt;xsl:output&nbsp;method="html"&nbsp;encoding="utf-8"&nbsp;indent="yes"/&gt;<br />&nbsp;&lt;xsl:template&nbsp;match="allusers"&gt;<br />&nbsp;&nbsp;&lt;html&gt;&lt;body&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Users&lt;/h2&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;table&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:for-each&nbsp;select="user"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;&lt;td&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:value-of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select="php:function('ucfirst',string(uid))"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:for-each&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;<br />&nbsp;&nbsp;&lt;/body&gt;&lt;/html&gt;<br />&nbsp;&lt;/xsl:template&gt;<br />&lt;/xsl:stylesheet&gt;<br /></span><span style="color: #007700">EOB;<br /></span><span style="color: #0000BB">$xmldoc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$xsldoc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsl</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$proc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">XSLTProcessor</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerPHPFunctions</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">importStyleSheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$xsldoc</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$proc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">transformToXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmldoc</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div></div>

    </div>
  </p>
 </div>

</div></div></div></body></html>